/*
 * $Id: sysapi_chdir.c,v 1.3 2005-12-26 07:41:48 bacon Exp $
 */

#include <xp/bas/sysapi.h>
#include <xp/bas/locale.h>
#include <xp/bas/errno.h>

int xp_chdir (const xp_char_t* path)
{
#ifdef _WIN32
	if (SetCurrentDirectory(path) == 0) {
		xp_seterrno (xp_maperrno(GetLastError()));
		return -1;
	}
	return 0;
#else

#ifdef XP_CHAR_IS_MCHAR
	return chdir (path);
#else
	xp_mchar_t path_mb[XP_PATH_MAX + 1];
	if (xp_wcstomcs_strict (
		path, path_mb, xp_countof(path_mb)) == -1) return -1;
	return chdir (path_mb);
#endif

#endif
}
